<template>
  <div class="table-container" ref="tableContainer">
    <el-table
      ref="dataTable"
      :data="tableData"
      :height="tableHeight"
      border
      :header-cell-style="{
        background: 'transparent',
        color: '#fff',
      }"
      :cell-style="{
        background: 'transparent',
        color: '#fff',
      }"
      :style="{
        background: 'transparent',
      }"
    >
      <el-table-column
        v-for="col in columns"
        :key="col.prop"
        :prop="col.prop"
        :label="col.label"
        :width="col.width"
      />
    </el-table>
  </div>
</template>

<script>
export default {
  name: 'DataTable',
  props: {
    chartData: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      tableHeight: 300,
      observer: null,
    }
  },
  computed: {
    columns() {
      return this.chartData.columns || []
    },
    tableData() {
      return this.chartData.data || []
    },
  },
  mounted() {
    this.initResizeObserver()
    this.updateTableHeight()
  },
  methods: {
    updateTableHeight() {
      if (this.$refs.tableContainer) {
        this.tableHeight = this.$refs.tableContainer.clientHeight - 20 // 减去padding
      }
    },
    initResizeObserver() {
      this.observer = new ResizeObserver(() => {
        this.updateTableHeight()
      })
      this.observer.observe(this.$refs.tableContainer)
    },
  },
  beforeDestroy() {
    if (this.observer) {
      this.observer.disconnect()
    }
  },
}
</script>

<style scoped>
.table-container {
  width: 100%;
  height: 100%;
  padding: 10px;
  background: transparent;
}

:deep(.el-table) {
  background: transparent !important;
}

:deep(.el-table__inner-wrapper) {
  background: transparent !important;
}

:deep(.el-table__header-wrapper),
:deep(.el-table__body-wrapper) {
  background: transparent !important;
}

:deep(.el-table tr),
:deep(.el-table th),
:deep(.el-table td) {
  background: transparent !important;
}

:deep(.el-table--border::after),
:deep(.el-table--group::after),
:deep(.el-table::before) {
  background-color: transparent !important;
}

:deep(.el-table td),
:deep(.el-table th.is-leaf) {
  border-color: rgba(255, 255, 255, 0.1);
}

:deep(.el-table--border) {
  border-color: rgba(255, 255, 255, 0.1);
}

:deep(.el-table--border) th,
:deep(.el-table--border) td {
  border-color: rgba(255, 255, 255, 0.1) !important;
}

:deep(.el-table__empty-block) {
  background: transparent !important;
}

:deep(.el-table__empty-text) {
  color: #fff;
}

/* 修改表格的滚动条样式 */
:deep(.el-table__body-wrapper::-webkit-scrollbar) {
  width: 6px;
  height: 6px;
}

:deep(.el-table__body-wrapper::-webkit-scrollbar-thumb) {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 3px;
}

:deep(.el-table__body-wrapper::-webkit-scrollbar-track) {
  background: transparent;
}
</style> 